function getSelector(path){
    return path.reverse().filter(element => {
        return element !== document && element !== window;
    }).map(element => {
        let selector = '';
        if(element.id){
            return `${element.nodeName.toLowerCase()}#${element.id}`
        } else if(element.className && typeof element.className === 'string'){
            return `${element.nodeName.toLowerCase()}.${element.className}`
        } else{
            selector = element.nodeName.toLowerCase()
        }
        return selector;
    }).join(' ')
}

let nodes = []
function getSelectorByParentNode(target){
    nodes.push(target.nodeName.toLowerCase())
    if(target.parentNode && target.parentNode.nodeName!=='#document'){
        getSelectorByParentNode(target.parentNode)
    }
    return nodes.reverse().join(' ');
}

export default function(event) {
    if(!event){
        return null;
    }
    if(Array.isArray(event.path)){
        return getSelector(event.path);
    } else if(!event.path){
        nodes = [];
        return getSelectorByParentNode(event.target);
    }
}